package redis

import (
	"fmt"
	"github.com/go-redis/redis"
	"time"
)

const (
	EXPIRED_LONG = 180 * time.Second //180秒

	EXPIRED_MEDIUM = 120 * time.Second //120秒

	EXPIRED_SHORT = 30 * time.Second // 30秒

	EXPIRED_DAY = 86400 * time.Second // 一天
)

func Set(key string, value interface{}, expiration time.Duration) {
	err := rdb.Set(key, value, expiration).Err()
	if err != nil {
		panic(err)
	}
}
func Get(key string) (value string, err error) {
	value, err = rdb.Get(key).Result()
	if err == redis.Nil {
		return "", nil
	} else if err != nil {
		return "", nil
	} else {
		return value, nil
	}
}
func Del(key string) {
	// 删除key
	err := rdb.Del(key).Err()
	if err != nil {
		fmt.Println("删除失败：", err)
	} else {
		fmt.Println("删除成功！")
	}
}
